#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QPoint>
#include <QTextItem>
#include <QColor>
#include <QString>
#include <sstream>
#include <QMessageBox>
#include <string>
#include <cctype>
#include <QPoint>
#include <QMouseEvent>
#include <QTimer>

#include "csudoku.h"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT
signals:
    void I_want_update_this_pane();
public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private slots:
    void on_inputData_textChanged();

  //  void on_showStart_clicked();
  //  void on_showStop_clicked();
    void updateThis();

    void on_showStart_clicked();

    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);



    void on_PB_exit_clicked();

    void on_PB_toMin_clicked();

    void on_L_ad_linkActivated(const QString &link);


    void on_HS_speed_sliderMoved(int position);

private:
    Ui::Widget *ui;
    QPainter *paint;

    //draw 的偏移量
    const int tmpx = 20;
    const int tmpy = 20;

    //保存数据
    QColor mpColor[9][9];
    QColor bgColor[9][9];
    QString mpValue[9][9];
    int mp[9][9];
    bool row[9][9];
    bool col[9][9];
    bool grid[9][9];

    //读取数据，检查数据
    int tmpValue[1000];
    CSudoku *tmpSudoku;
    //检查数独
    bool checkSudoku();
    //解决数独
    void solve();
    //搜索解法
    bool mydfs(const int &x,const int &y);
    //更新界面
    void updatePane();
    //没有标题栏，移动窗口
    bool    m_MousePressed;
    QPoint  m_MousePos;
    QPoint  m_WindowPos;
    void sleep(unsigned int msec);
    void paintEvent(QPaintEvent *);

    void try_Point(int x,int y);
    void try_P_val(int x,int y,int k);
    void cal_P_val(int x,int y,int k);
    void set_P_val(int x,int y);
    void del_P_val(int x,int y);

    void init();
    void debug();
};

#endif // WIDGET_H
